home *** CD-ROM | disk | FTP | other *** search
- //: C19:Sorted.cpp
- // From Thinking in C++, 2nd Edition
- // Available at http://www.BruceEckel.com
- // (c) Bruce Eckel 1999
- // Copyright notice in Copyright.txt
- // Testing template specialization
- #include "Sorted.h"
- #include "Urand.h"
- #include "../arraySize.h"
- #include <iostream>
- #include <string>
- using namespace std;
-
- char* words[] = {
- "is", "running", "big", "dog", "a",
- };
- char* words2[] = {
- "this", "that", "theother",
- };
-
- int main() {
- Sorted<int> is;
- Urand<47> rand;
- for(int i = 0; i < 15; i++)
- is.push_back(rand());
- for(int l = 0; l < is.size(); l++)
- cout << is[l] << ' ';
- cout << endl;
- is.sort();
- for(int l = 0; l < is.size(); l++)
- cout << is[l] << ' ';
- cout << endl;
-
- // Uses the template partial specialization:
- Sorted<string*> ss;
- for(int i = 0; i < asz(words); i++)
- ss.push_back(new string(words[i]));
- for(int i = 0; i < ss.size(); i++)
- cout << *ss[i] << ' ';
- cout << endl;
- ss.sort();
- for(int i = 0; i < ss.size(); i++)
- cout << *ss[i] << ' ';
- cout << endl;
-
- // Uses the full char* specialization:
- Sorted<char*> scp;
- for(int i = 0; i < asz(words2); i++)
- scp.push_back(words2[i]);
- for(int i = 0; i < scp.size(); i++)
- cout << scp[i] << ' ';
- cout << endl;
- scp.sort();
- for(int i = 0; i < scp.size(); i++)
- cout << scp[i] << ' ';
- cout << endl;
- } ///:~
-